
/**
 * 经纬度坐标转球面坐标
 * @param {地球半径} R
 * @param {经度(角度值)} longitude
 * @param {维度(角度值)} latitude
 */
export function lon2xyz(R, longitude, latitude) {
    var lon = (longitude * Math.PI) / 180; 
    var lat = (latitude * Math.PI) / 180;
    lon = -lon; 
  
    var x = R * Math.cos(lat) * Math.cos(lon);
    var y = R * Math.sin(lat);
    var z = R * Math.cos(lat) * Math.sin(lon);

    return {
      x: x,
      y: y,
      z: z,
    };
  }
  
  export const isType = function (type, value) {
    return Object.prototype.toString.call(value) === `[object ${type}]`;
  };
  /**
   * 判断是否为对象
   */
  export const isObject = function (value) {
    return isType('Object', value);
  };
  /**
   * @description deepClone() 深拷贝-最终版：解决循环引用的问题
   * @param {*} target 对象
   * @example
   *      const obj1 = {
   *          a: 1,
   *          b: ["e", "f", "g"],
   *          c: { h: { i: 2 } },
   *      };
   *      obj1.b.push(obj1.c);
   *      obj1.c.j = obj1.b;
   *
   *      const obj2 = deepClone(obj1);
   *      obj2.b.push("h");
   *      console.log(obj1, obj2);
   *      console.log(obj2.c === obj1.c);
   */
  export function deepClone(target, map = new Map()) {
    if (target != null && isObject(target)) {
      let cache = map.get(target);
      if (cache) {
        return cache;
      }
      const isArray = Array.isArray(target);
      let result = isArray ? [] : {};
      cache = map.set(target, result);
      if (isArray) {
        target.forEach((item, index) => {
          result[index] = deepClone(item, cache);
        });
      } else {
        Object.keys(target).forEach((key) => {
          if (isObject(result[key])) {
            result[key] = deepClone(target[key], cache);
          } else {
            result[key] = target[key];
          }
        });
      }
      return result;
    } else {
      return target;
    }
  }
  
  export function deepMerge(target, source) {
    target = deepClone(target);
    for (let key in source) {
      if (key in target) {
        if (isObject(source[key])) {
          if (!isObject(target[key])) {
            target[key] = source[key];
          } else {
            target[key] = deepMerge(target[key], source[key]);
          }
        } else {
          target[key] = source[key];
        }
      } else {
        target[key] = source[key];
      }
    }
    return target;
  }
  export const random = function (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  };
  /**
   * 获取样式
   * @param {*} el
   * @param {*} ruleName
   * @returns
   */
  export function getStyle(el, ruleName) {
    return window.getComputedStyle(el)[ruleName];
  }
  